package com.ruoyi.movie.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.movie.domain.Cast;
import com.ruoyi.movie.service.ICastService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 演职人员管理Controller
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/movie/cast")
public class CastController extends BaseController
{
    @Autowired
    private ICastService castService;

    /**
     * 查询演职人员列表
     */
    @PreAuthorize("@ss.hasPermi('movie:cast:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cast cast)
    {
        startPage();
        List<Cast> list = castService.selectCastList(cast);
        return getDataTable(list);
    }

    /**
     * 获取演职人员详细信息
     */
    @PreAuthorize("@ss.hasPermi('movie:cast:query')")
    @GetMapping(value = "/{castId}")
    public AjaxResult getInfo(@PathVariable("castId") Long castId)
    {
        return AjaxResult.success(castService.selectCastById(castId));
    }

    /**
     * 新增演职人员
     */
    @PreAuthorize("@ss.hasPermi('movie:cast:add')")
    @Log(title = "演职人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cast cast)
    {
        return toAjax(castService.insertCast(cast));
    }

    /**
     * 修改演职人员
     */
    @PreAuthorize("@ss.hasPermi('movie:cast:edit')")
    @Log(title = "演职人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cast cast)
    {
        return toAjax(castService.updateCast(cast));
    }

    /**
     * 删除演职人员
     */
    @PreAuthorize("@ss.hasPermi('movie:cast:remove')")
    @Log(title = "演职人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{castIds}")
    public AjaxResult remove(@PathVariable Long[] castIds)
    {
        return toAjax(castService.deleteCastByIds(castIds));
    }

    /**
     * 获取影视的演职人员列表
     */
    @GetMapping("/movie/{movieId}")
    public AjaxResult getMovieCast(@PathVariable("movieId") Long movieId)
    {
        return AjaxResult.success(castService.selectCastByMovieId(movieId));
    }
}